

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="__STATIC__/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="__STATIC__/module/eleTree/eleTree.css" media="all">
</head>
<body>

<div class="layui-form" lay-filter="layuiadmin-form-role" id="layuiadmin-form-role" style="padding: 20px 30px 0 0;">

    <div class="layui-form-item">
        <label class="layui-form-label">名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="required" autocomplete="off" class="layui-input" value="{$data.name}">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">权限</label>
        <div class="layui-input-inline">
            <div id="LAY-auth-tree-index"></div>
        </div>
    </div>

    <input type="hidden" name="id" value="{$data.id}">

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit lay-filter="*">提交</button>
        </div>

    </div>
</div>

<script src="__STATIC__/layuiadmin/layui/layui.js"></script>
<script src="__STATIC__/js/base.js"></script>
<script>
    layui.config({
        base: '__STATIC__/module/'
    }).extend({
        authtree: 'authtree/authtree'
    }).use(['form','authtree','layer'], function () {
        var form = layui.form
            ,$ = layui.jquery
            ,layer = layui.layer
            ,authtree = layui.authtree
            ,menuIds = [];

        form.on('submit(*)', function(data){
            $.post("{:url('user/userRoleSave')}",data.field,function (ret) {
                if (ret.code == 0){
                    layer.msg(ret.msg,{icon:6,time:1500},function () {
                        parent.layer.closeAll();
                        parent.layui.table.reload("KT_table")
                    })
                }else{
                    layer.msg(ret.msg,{icon:5,time:1500})
                }
            });
            return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        $.ajax({
            url: "{:url('user/getMenu',['role_id'=>$data.id])}",
            dataType: 'json',
            success: function(data){
                // 渲染时传入渲染目标ID，树形结构数据（具体结构看样例，checked表示默认选中），以及input表单的名字
                authtree.render('#LAY-auth-tree-index', data.data, {inputname: 'menu_id[]', layfilter: 'lay-check-auth', openall: true,nameKey:"title",valueKey:"id"});


            }
        })

    })
</script>
</body>
</html>